// My Computer Program for PCMod (CLIENT)

PROG.PName = "MyComputer"
PROG.Author = "[GU]|ZLC|thomasfn"

PROG.Icon = "icons/ico_ctrl"

PROG.NiceName = "My Computer" -- Shown on the 2D 3D Screen

function PROG:BuildWindow( WindowName, Desktop, Object )
	// Here we build the derma window.
	// Note the Desktop string is needed for every operation involving derma.
	
	// Enable the tools icon
	// self:SetEnableTools( true )
	
	SendCommand( "update" )
	
	if (WindowName == "Main") then
		// Add a title label
		//DInterface:AddLabel( "lblTitle", Desktop, "My Computer - Control Panel", 5, 5 )
		
		// Add the network settings section
		DInterface:AddLabel( "lblInfo", Desktop, "Static ID:", 5, 25 )
		DInterface:AddTextbox( "txtIP", Desktop, "1", 105, 25, 50, 20 )
		DInterface:AddButton( "btnGo", Desktop, "Apply", 5, Object:GetTall()-25, 120, 20, function( self )
			RunConsoleCommand( "pc_command", "setpip", DInterface:GetTextboxValue( "txtIP", Desktop ) )
			local lineid = DInterface:GetTableSelectedLine( "tblThemes", Desktop, "Theme Name" )
			if ((lineid) && (lineid != 0)) then
				local tname = DInterface:GetObject( "tblThemes", "tbl", Desktop ).Lines[ lineid ].TName
				RunConsoleCommand( "pc_command", "settheme", tname )
			end
			if (C_PRO.CC) then
				local r = C_PRO.CC:GetRGB().r
				local g = C_PRO.CC:GetRGB().g
				local b = C_PRO.CC:GetRGB().b
				RunConsoleCommand( "pc_command", "setdr", r )
				RunConsoleCommand( "pc_command", "setdg", g )
				RunConsoleCommand( "pc_command", "setdb", b )
			end
		end )
		DInterface:AddLabel( "lblIP", Desktop, CurrentPC:GetNWString( "IP" ), 5, 40 )
		
		// Add the desktop colour chooser section
		DInterface:AddLabel( "lblInfo2", Desktop, "Desktop Colour:", 200, 25 )
		self.CC = vgui.Create( "DColorCircle", Object )
		self.CC:SetPos( 200, 50 )
		self.CC:SetSize( 150, 150 )
		self.CC:SetRGB( Color( CurrentPC:GetNWInt( "OS_DesktopR" ), CurrentPC:GetNWInt( "OS_DesktopG" ), CurrentPC:GetNWInt( "OS_DesktopB" ) ) )
		
		// Add the change password section
		DInterface:AddLabel( "lblInfo3", Desktop, "Change Password: ", 5, 60 )
		DInterface:AddLabel( "lblInfo4", Desktop, "Old: ", 5, 80 )
		DInterface:AddLabel( "lblInfo5", Desktop, "New: ", 5, 100 )
		DInterface:AddLabel( "lblInfo6", Desktop, "", 5, 140 )
		DInterface:AddTextbox( "txtOPass", Desktop, "", 55, 80, 140, 20 )
		DInterface:AddTextbox( "txtNPass", Desktop, "", 55, 100, 140, 20 )
		DInterface:AddButton( "btnChange", Desktop, "Change", 5, 120, 120, 20, function( self )
			SendCommand( "changepass",
				DInterface:GetTextboxValue( "txtOPass", Desktop ),
				DInterface:GetTextboxValue( "txtNPass", Desktop ) 
			)
		end )
		
		// Add the theme chooser section
		DInterface:AddTable( "tblThemes", Desktop, 5, 150, 180, Object:GetTall()-210 )
		DInterface:TableAddColumn( "tblThemes", Desktop, "Theme Name" )
		DInterface:TableAddColumn( "tblThemes", Desktop, "Theme Author" )
		for k, v in pairs( ThemeList ) do
			local line = DInterface:TableAddRow( "tblThemes", Desktop, v.NiceName, v.Author )
			line.TName = v.ThemeName
		end
		
		self.Desktop = Desktop
		
	end
	
	// Add a quit button
	DInterface:AddButton( "btnQuit", Desktop, "X", Object:GetWide()-20, 0, 20, 20, function() SendCommand( "quit" ); end )
end

function PROG:ClearWindow( Desktop )
	// Here we destroy EVERY derma control that MIGHT exist.
	
	// Disable the tools icon
	self:SetEnableTools( false )
	
	DInterface:RemoveLabel( "lblTitle", Desktop )
	
	DInterface:RemoveLabel( "lblInfo", Desktop )
	DInterface:RemoveTextbox( "txtIP", Desktop )
	DInterface:RemoveButton( "btnGo", Desktop )
	DInterface:RemoveLabel( "lblIP", Desktop )
	
	DInterface:RemoveLabel( "lblInfo2", Desktop )
	if (self.CC) then self.CC:Remove(); self.CC = nil; end
	
	DInterface:RemoveLabel( "lblInfo3", Desktop )
	DInterface:RemoveLabel( "lblInfo4", Desktop )
	DInterface:RemoveLabel( "lblInfo5", Desktop )
	DInterface:RemoveLabel( "lblInfo6", Desktop )
	DInterface:RemoveTextbox( "txtOPass", Desktop )
	DInterface:RemoveTextbox( "txtNPass", Desktop )
	DInterface:RemoveButton( "btnChange", Desktop )
	
	DInterface:RemoveTable( "tblThemes", Desktop )
	
	DInterface:RemoveButton( "btnQuit", Desktop )
end

// Data[1] = Tag
// Data[2] = Content
function PROG:DataRecieved( Desktop, Data )
	// The server has sent us some data
	if (Data[1] == "p_ip") then DInterface:SetTextboxText( "txtIP", Desktop, tostring( Data[2] ) ) end
	if (Data[1] == "pinfo") then DInterface:SetLabelText( "lblInfo6", Desktop, Data[2] ) end
end

function PROG:Paint( x, y, w, h )
	// draw.SimpleText( self.NiceName, "SmallPCText", x + (w*0.05), y + (h*0.05), Color( 255, 255, 255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
end